package excercise;

import java.util.Scanner;

import org.omg.CORBA.OMGVMCID;

public class EX03_Q20 {

	public static void main(String[] args) {
		//#20
		int a = 3;
		if (a ++ == 3 ) {
			System.out.println( a );
			System.out.println( "Three" );
		} else
			System.out.println( "Four" );
		
		// 후치 증가연산자
		// 변수의 값이 먼저 식에 적용되고
		// 그 후에 값이 증가됨
		
		int b = 3;
		if ( ++b == 3 ) {
			System.out.println( "Three" );
		} else
			System.out.println( "Four" );
		// 전치 증가연산자
		// 먼저 변수의 값을 증가시킨 후
		// 그 값을 식에 적용함
		
		int c = 3;
		c = c++;
		if ( c == 3 ) {
			System.out.println( "Three" );
		} else
			System.out.println( "Four" );
		
		int d = 3;
		d = ++d;		// ++d 와 동일
		if ( d == 3 ) {
			System.out.println( "Three" );
		} else
			System.out.println( "Four" );
		
		int e = 3;
		e++;	
		if ( e == 3 ) {
			System.out.println( "Three" );
		} else
			System.out.println( "Four" );
		
		int f = 3;
		++f;	
		if ( f == 3 ) {
			System.out.println( "Three" );
		} else
			System.out.println( "Four" );
		
		// #21
		int salary = 17500;
		boolean isMarried = false;
		float tax = 0.0F;
		
		if ( isMarried == true ) {				// 기혼인 경우
			if ( salary < 6000 ) tax = salary * 0.1F;
			else if ( salary >= 6000 ) tax = salary * 0.25F;
		} else if ( isMarried == false ) {	// 미혼인 경우
			if ( salary < 3000 ) tax = salary * 0.1F;
			else if (salary >= 3000 ) tax = salary * 0.25F;
		}
		System.out.println( isMarried );
		System.out.println( salary );
		System.out.println( tax );
		
		//#22
		int thisYear = 2014;
		
		if ( thisYear % 4 == 0 && thisYear % 100  != 0 )
			System.out.println( "윤년입니다!~" );
		else if ( thisYear % 400 == 0 )
			System.out.println( "윤년입니다!~" );
		else 
			System.out.println( "윤년이 아닙니다!~" );
		
		
		//#30
		System.out.println( "                             Multiplication Table" );
		System.out.println( "           1       2       3       4       5       6       7       8       9" );
		System.out.println( "----------------------------------------------------------" );
		// System.out.println( "1  |      1       2       3       4       5       6       7       8       9" );
		
		for ( int i = 1; i <= 9; ++i ) {
			if ( i == 1 ) System.out.print( (i*1) + "  |" );
			System.out.print( "       " + (i*1) );
		}
		System.out.println(  );    		// 줄바꿈
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*2) + "  |" );
			System.out.print( "       " + (i*2) );
		}
		System.out.println(  );    		// 줄바꿈
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*3) + "  |" );
			System.out.print( "       " + (i*3) );
		}
		System.out.println(  ); 
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*4) + "  |" );
			System.out.print( "       " + (i*4) );
		}
		System.out.println(  ); 
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*5) + "  |" );
			System.out.print( "       " + (i*3) );
		}
		System.out.println(  ); 
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*6) + "  |" );
			System.out.print( "       " + (i*6) );
		}
		System.out.println(  ); 
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*7) + "  |" );
			System.out.print( "       " + (i*7) );
		}
		System.out.println(  ); 
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*8) + "  |" );
			System.out.print( "       " + (i*8) );
		}
		System.out.println(  ); 
		
		for ( int i = 1; i <= 9; ++i  ) {
			if ( i == 1 ) System.out.print( (i*9) + "  |" );
			System.out.print( "       " + (i*9) );
		}
		System.out.println(  ); 
		
		/*****************************************************/
		for ( int j = 1; j <= 9; ++j ) {
			for ( int i = 1; i <= 9; ++i  ) {
				if ( i == 1 ) System.out.print( (i * j) + "  |" );
				System.out.print( "\t" + (i * j) );
			}
			System.out.println(  ); 
		}
		
		//#26
		int myNum = 0;
		int comNum = 0;
		Scanner sc = new Scanner( System.in );
		
		comNum = (int)(Math.random() * 100) + 1;
		while( myNum != comNum ) {
			System.out.println(
						"1 - 100 사이 숫자를 입력하세요 ");
			myNum = sc.nextInt();
			
			if ( myNum > comNum )
				System.out.println( "추측한 값이 큽니다" );
			else if ( myNum < comNum )
				System.out.println( "추측한 값이 작습니다" );
			else 
				System.out.println( "빙고! 맞췄습니다" );
		}
		
		//#23
		int[] myLotto = new int[4];
		int[] comLotto = new int[4];
		int match = 0;			// 일치횟수
		
		// comLotto = (int)(Math.random() *1000) +1;
		// 0.123456789 : 1000 => 123.456789 => 124
		// 0.000123456 : 1000 => 0.123455 => 1 
		
		//comLotto[1] = (int)(Math.random() *10);		
		//comLotto[2] = (int)(Math.random() *10);		
		//comLotto[3] = (int)(Math.random() *10);		
		
		// 컴퓨터 복권 3자리 생성
		for (int i = 1; i < comLotto.length; ++i)
			comLotto[ i ] = (int)(Math.random() *10);
		
		// 사용자로부터 3자리 입력받기
		sc = new Scanner( System.in );
		for(int i = 1; i < myLotto.length; ++i)	{
			System.out.println( i + " 번째 숫자를 입력하세요" );
			myLotto[i] = sc.nextInt();
		}
		
		// 비교
		// 123 : 123, 213, 312, 231
		if ( myLotto[1] == comLotto[1] || 
			 myLotto[1] == comLotto[2] ||
			 myLotto[1] == comLotto[3] ) ++match;
		
		if ( myLotto[2] == comLotto[1] || 
			 myLotto[2] == comLotto[2] ||
			 myLotto[2] == comLotto[3] ) ++match;			
					
		if ( myLotto[3] == comLotto[1] || 
			 myLotto[3] == comLotto[2] ||
			 myLotto[3] == comLotto[3] ) ++match;
		
		// 일치여부에 따라 상금 부여
		if (match == 1) 
			System.out.println( "3등 당첨! 상금 1000원 수령" );
		else if (match == 2)
			System.out.println( "2등 당첨! 상금 10000원 수령" );
		else if (match == 3) 
			System.out.println( "1등 당첨! 상금 백만원 수령" );
		else 
			System.out.println( "꽈~앙~ 다음 기회에~" );
	
		System.out.print( "추첨번호 : ");
		for (int i = 1; i <= 3; ++i) 
				System.out.print( comLotto[i] + "\t");
		System.out.print( "\n복권번호 : ");
		for (int i = 1; i <= 3; ++i) 
				System.out.print( myLotto[i] + "\t");
		
	}

}



